# #Lagos download script
LAGOSNE::lagosne_get(dest_folder = LAGOSNE:::lagos_path())
#Load in lagos
lagos <- lagosne_load()
#Grab the lake centroid info
lake_centers <- lagos$locus
#Look at the column names
#names(lake_centers)
#Look at the structure
#str(lake_centers)
#View the full dataset
#View(lake_centers %>% slice(1:100))
spatial_lakes <- st_as_sf(lake_centers,coords=c('nhd_long','nhd_lat'),
crs=4326) %>%
st_transform(2163)
#Subset for plotting
subset_spatial <- spatial_lakes %>%
slice(1:100)
subset_baser <- spatial_lakes[1:100,]
#Dynamic mapviewer
mapview(subset_spatial)
states <- us_states()
#Plot all the states to check if they loaded
#mapview(states)
minnesota <- states %>%
filter(name == 'Minnesota') %>%
st_transform(2163)
#Subset lakes based on spatial position
minnesota_lakes <- spatial_lakes[minnesota,]
#Plotting the first 1000 lakes
minnesota_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')
#Plotting Illinois and Iowa on same map:
illinois_iowa <- states %>%
arrange(name)%>%
filter(name %in% c('Illinois','Iowa'))%>%
st_transform(2163)
mapview(illinois_iowa)
#Subset lakes based on spatial position
illinois_iowa_lakes <- spatial_lakes[illinois_iowa,]
# ddply(illinois_iowa_lakes,.(lagoslakeid),nrow)
str(illinois_iowa_lakes)
## Classes 'sf' and 'data.frame': 16466 obs. of 17 variables:
## $ lagoslakeid : int 4280 4285 4292 4312 4314 4322 4351 4363 4389 4393 ...
## $ nhdid : chr "155844663" "137027971" "132548442" "146615193" ...
## $ gnis_name : chr "Eldred Sherwood Park Lake" "Badger Lake" NA NA ...
## $ lake_area_ha : num 8.59 17.27 3.97 10.68 208.45 ...
## $ lake_perim_meters: num 2747 4146 1603 2323 18841 ...
## $ nhd_fcode : int 39004 39004 39004 39004 39004 39004 39004 39009 39004 39004 ...
## $ nhd_ftype : int 390 390 390 390 390 390 390 390 390 390 ...
## $ iws_zoneid : chr "IWS_31926" "IWS_32272" NA "IWS_3378" ...
## $ hu4_zoneid : chr "HU4_57" "HU4_56" "HU4_61" "HU4_56" ...
## $ hu6_zoneid : chr "HU6_78" "HU6_79" "HU6_87" "HU6_79" ...
## $ hu8_zoneid : chr "HU8_400" "HU8_403" "HU8_419" "HU8_406" ...
## $ hu12_zoneid : chr "HU12_9763" "HU12_3119" "HU12_2466" "HU12_3425" ...
## $ edu_zoneid : chr "EDU_23" "EDU_74" "EDU_4" "EDU_61" ...
## $ county_zoneid : chr "County_248" "County_204" "County_207" "County_251" ...
## $ state_zoneid : chr "State_13" "State_13" "State_13" "State_13" ...
## $ elevation_m : num 372 328 340 287 266 ...
## $ geometry :sfc_POINT of length 16466; first list element: 'XY' num 524845 -208157
## - attr(*, "sf_column")= chr "geometry"
## - attr(*, "agr")= Factor w/ 3 levels "constant","aggregate",..: NA NA NA NA NA NA NA NA NA NA ...
## ..- attr(*, "names")= chr [1:16] "lagoslakeid" "nhdid" "gnis_name" "lake_area_ha" ...
There are 16,466 different sites in Illinois and Iowa combined.
In Minnesota alone there are 29,038 sites.
# What is the "state_zoneid" value for Iowa?
## (We already know that Minnesota's state_zoneid = State_14)
## Confirmed that Iowa = State_13
# iowa <- states %>%
# arrange(name)%>%
# filter(name %in% c('Iowa'))%>%
# st_transform(2163)
# mapview(iowa)
#
# iowa_lakes <- spatial_lakes[iowa,]
# str(iowa_lakes)
(Found that Iowa indeed has state_zoneid of “State_13” in the spatial_lakes data.)
# Getting Minnesota vs Iowa Data in one sf dataframe
## creating spatial filter boundary:
minnesota_iowa <- states %>%
arrange(name)%>%
filter(name %in% c('Minnesota','Iowa'))%>%
st_transform(2163)
mapview(minnesota_iowa)
## filtering data by area, creating state_name column, removing unneccesary data
minnesota_iowa_lakes <- spatial_lakes[minnesota_iowa,] %>%
mutate(state_name = case_when(state_zoneid == "State_14" ~ "Minnesota",
state_zoneid == "State_13" ~ "Iowa",
TRUE ~ "error")) %>%
select(lake_area_ha,state_name)%>%
filter(!state_name == "error")
arrange(minnesota_iowa_lakes, state_name, lake_area_ha)
## Simple feature collection with 33611 features and 2 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: 203919.6 ymin: -480215.1 xmax: 813541.2 ymax: 493918.3
## Projected CRS: NAD27 / US National Atlas Equal Area
## First 10 features:
## lake_area_ha state_name geometry
## 1 1.000077 Iowa POINT (742604 -379229.3)
## 2 1.000400 Iowa POINT (515669.8 -337658.9)
## 3 1.000417 Iowa POINT (507368.8 -450353.2)
## 4 1.000624 Iowa POINT (580891.2 -370334.6)
## 5 1.000978 Iowa POINT (692479.6 -410089.1)
## 6 1.000999 Iowa POINT (470411.5 -418019.3)
## 7 1.001508 Iowa POINT (476085.4 -409184)
## 8 1.001624 Iowa POINT (510446 -468205.6)
## 9 1.001692 Iowa POINT (367883 -472857)
## 10 1.001693 Iowa POINT (602137.5 -337188.5)
# creating histogram:
ggplot(minnesota_iowa_lakes, aes(x=log10(lake_area_ha), fill=state_name)) +
geom_histogram( color="#e9ecef", alpha=0.6, position = 'identity') +
scale_fill_manual(values=c("#404080", "#69b3a2")) +
theme_ipsum() +
labs(fill="")
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Comparing the distributions of lake size on the log10 scale for Iowa on top of Minnesota reveals that the both states have very similar lake area distributions. Minnesota has more lakes than Iowa, but the distribution of those lake by area is very comparable to Iowa. Minnesota also appears to have larger lakes than Iowa.
# Creating interactive map for the largest 1000 lakes across Illinois and Iowa
illinois_iowa_lakes %>%
arrange(-lake_area_ha) %>%
slice(1:1000) %>%
mapview(.,zcol = 'lake_area_ha')
We could perhaps analyze some of the shapefiles that USGS provides for North American lakes: https://www.sciencebase.gov/catalog/item/4fb55df0e4b04cb937751e02